package converters;
  
import javax.faces.component.UIComponent;  
import javax.faces.context.FacesContext;  
import javax.faces.convert.Converter;  
import javax.faces.convert.FacesConverter;

import structures.ValuePair;
  
@FacesConverter(value="valuePairConverter")
public class ValuePairConverter implements Converter {  
  
    public Object getAsObject(FacesContext facesContext, UIComponent component, String submittedValue) {  
    	ValuePair s = null;
		if (submittedValue.trim().equals("")) {  
		    return null;  
		} else { 
			s = new ValuePair(submittedValue);
		}
        return s;
    }  
  
    public String getAsString(FacesContext facesContext, UIComponent component, Object value) {
        if (value == null) {  
            return "";  
        } else if (value instanceof ValuePair){  
            return String.valueOf(((ValuePair) value).getValue());  
        } else {
        	return value.toString();
        }
    }  
    
    
}  